layui.define([ 'form', 'laydate', 'table','siteFundsApi'], function(exports) {
    var form = layui.form;
    var siteFundsApi = layui.siteFundsApi;
    var index = layui.index;
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                 form.on('submit(form)', function(){
                     /**
                      * 获取身份证文件
                      */

                     var copiesDocuments = Common.fileRequire("#copiesDocumentsDataList");
                     var proofMaterial = Common.fileRequire("#proofMaterialDataList");

                     if(copiesDocuments){
                         Common.alert("国家或省博管办同意设站的批文复印件附件必须上传");
                     }else if(proofMaterial){
                         Common.alert("市经费资助证明材料附件必须上传");
                     }else {
                         siteFundsApi.addSiteFunds($('#addForm'), function () {
                             parent.window.dataReload();
                             Common.info("添加成功");
                             Lib.closeFrame();
                         });
                     }
                });
            });

            $("#addButton-PandD").click(function(){
                form.on('submit(form)', function() {
                    /**
                     * 获取身份证文件
                     */

                    var copiesDocuments = Common.fileRequire("#copiesDocumentsDataList");
                    var proofMaterial = Common.fileRequire("#proofMaterialDataList");

                    if (copiesDocuments) {
                        Common.alert("国家或省博管办同意设站的批文复印件附件必须上传");
                    } else if (proofMaterial) {
                        Common.alert("市经费资助证明材料附件必须上传");
                    } else {
                    Common.openConfirm("确认申报?", function () {
                        siteFundsApi.savedeclaration($('#addForm'), function () {
                            parent.window.dataReload();
                            Common.info("保存并申报成功");
                            Lib.closeFrame();
                        });
                    }, null);
                }
                });
            });

            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }
    			
    }
    exports('add',view);
});